<template>
  <page-content
    ref="contentRef"
    :content-config="contentConfig"
    @export-click="handleExportClick"
    @operat-click="handleOperatClick"
  >
    <template #status="scope">
      <el-tag v-if="scope.row[scope.status] == 3" type="success">{{
        statusMap[scope.row.status]
      }}</el-tag>
      <el-tag v-else-if="scope.row[scope.status] == 4" type="info">{{
        statusMap[scope.row.status]
      }}</el-tag>
      <el-tag v-else-if="statusMap[scope.row.status]">{{
        statusMap[scope.row.status]
      }}</el-tag>
    </template>
  </page-content>
</template>
<script setup>
import UserAPI from "@/api/order";
import usePage from "@/hooks/usePage";
import contentConfig from "./config/content";
const statusMap = {
  0: "待预约",
  1: "已预约",
  2: "已派单",
  3: "已完成",
  4: "交易关闭",
};
const { contentRef, handleExportClick } = usePage();
// 其他操作列
function handleOperatClick(data) {
  // 重置密码
  if (data.name === "dispatch") {
    ElMessageBox.confirm("确认派单吗？", "提示", {
      confirmButtonText: "确定",
    }).then(() => {
      UserAPI.patch(data.row.id)
        .then((res) => {
          contentRef.value?.fetchPageData({}, false);
          ElMessage.success("成功!");
        })
        .catch((err) => {});
    });
  } else if (data.name === "complete") {
    ElMessageBox.confirm("确认完成订单吗？", "提示", {
      confirmButtonText: "确定",
    }).then(() => {
      UserAPI.complete(data.row.id)
        .then((res) => {
          contentRef.value?.fetchPageData({}, false);
          ElMessage.success("成功!");
        })
        .catch((err) => {});
    });
  }
}
</script>
<style scoped>
:deep(.el-table__body tr.current-row > td.el-table__cell) {
  background-color: #fff;
}
</style>
